package com.roy.bio;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.Socket;

/**
 * @author ：楼兰
 * @date ：Created in 2021/6/2
 * @description:
 **/

public class BioClient {
    public static void main(String[] args) throws IOException {
        final Socket socket = new Socket("127.0.0.1", 8080);
        System.out.println("建立连接完成");
        //直接通过outputStream提交信息
        socket.getOutputStream().write(("我是客户端；"+socket.getLocalAddress()).getBytes());
        System.out.println("发送消息完成");
        //通过inputStream获取信息
        final InputStream inputStream = socket.getInputStream();
        byte[] buffer = new byte[1024];
        inputStream.read(buffer);
        System.out.println("收到服务端的响应："+new String(buffer));

        inputStream.close();
        socket.close();

    }
}
